package com.haibei.view.web;

import java.io.DataOutputStream;
import java.io.OutputStream;

import android.app.Activity;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;

public class DeviceUtils {
	/**
	 * 获取屏幕宽高的方法
	 * @param context
	 * @return 屏幕宽高数组
	 */
	public static int[] getDisplay(Activity context){
		Display display = context.getWindowManager().getDefaultDisplay();
		int[] screenPar = new int[2];
		screenPar[0] = display.getWidth();
		screenPar[1] = display.getHeight();
		return screenPar;
	}
	
	
	
	/**
	 * 判断手机有没有Root过
	 * @return
	 */
	public static boolean isDeviceRoot(){
		int i = execRootCmdSilent("echo test"); // 通过执行测试命令来检测
		if (i != -1)
			return true;
		return false;
	}
	
	/**
	 * 执行linux命令但不关注结果输出
	 */
	public static int execRootCmdSilent(String cmd) {
		try {
			Process process = Runtime.getRuntime().exec("su");
			OutputStream outputStream = process.getOutputStream();
			DataOutputStream dataOutputStream = new DataOutputStream(
					outputStream);

			dataOutputStream.writeBytes(cmd + "\n");
			dataOutputStream.flush();
			dataOutputStream.writeBytes("exit\n");
			dataOutputStream.flush();

			process.waitFor();
			return process.exitValue();
		} catch (Exception exception) {
			// 
		}
		return -1;
	}
	

}

